/**
 * Created by zhangligang
 * Email: tzhang2450@163.com
 * Date: 2018/11/23
 * Time: 22:38
 */
$(function(){
    var url = '/v1/check.json';
    var authorization = Cookies.get('_token');
    if (authorization != null || authorization != undefined) {
        $.ajax({
            type: 'get',
            url : url,
            headers: {
                Authorization: authorization,
                Accept: "application/json; charset=utf-8"
            },
            success: function(e) {
                var result = JSON.parse(e);
                if (result.status == 4031 || result.status == 4032) {
                    Cookies.set('_token', null, {path: '/'});
                    location.href = '/login.html';
                }
                if (result.status == 200) {
                    var json = result.body.data;
                    var uc = '';
                    if (json.role == 1) {
                        uc = '/student.html';
                    }
                    if (json.role == 2) {
                        uc = '/teacher.html';
                    }
                    if (json.role == 3) {
                        uc = '/manager.html';
                    }
                    if (location.href == '/login.html' || location.href == 'register.html') {
                        location.href = uc;
                    }
                }
            }
        })
    } else {
        Cookies.set('_token', null, {path: '/'});
        location.href = '/login.html';
    }
})